<extend name="Base/ucenter_common"/>
<block name="body">
    <style>
        .form {
            margin-top: 30px;
        }

    </style>
    <div class="widget-box">
        <div class="widget-header">
            <h3>修改密码：</h3>
        </div>
        <div class="widget-body">
            <div class="row">
                <form class="form col-md-5 col-md-offset-3" action="{:U('user/reset_pwd')}" method="post"
                      name="phone_change">
                    <div class="form-group">
                        <label>手机验证</label>
                        <div class="input-group" style="width: 100%;">
                            <input type="button" class="btn btn-get-phone" value="获取验证码"
                                   style="width: 30%;">
                            <input class="form-control" type="text" placeholder="请输入手机号"
                                   style="width: 70%;" maxlength="13" value="{$_user.u_user}" readonly="readonly">
                        </div>
                    </div>
                    <div class="form-group">
                        <label>验证码</label>
                        <div class="input-group">
                            <div class="input-group-addon"><span class="glyphicon glyphicon-envelope"></span></div>
                            <input class="form-control" type="text" placeholder="请输入手机验证码" name="check_code"
                                   maxlength="6">
                        </div>
                    </div>
                    <div class="form-group">
                        <label>旧密码</label>
                        <div class="input-group">
                            <span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></span>
                            <input class="form-control" type="password" placeholder="请输入密码" name="oldpassword"
                                   maxlength="15">
                        </div>
                    </div>
                    <div class="form-group">
                        <label>修改密码</label>
                        <div class="input-group">
                            <span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></span>
                            <input class="form-control" type="password" placeholder="请输入新密码" name="changepassword"
                                   maxlength="15">
                        </div>
                    </div>
                    <div class="form-group">
                        <label>确认新密码</label>
                        <div class="input-group">
                            <span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></span>
                            <input class="form-control" type="password" placeholder="请输入新密码" name="changepassword2"
                                   maxlength="15">
                        </div>
                    </div>
                    <div style="width: 70%;overflow: hidden;" class="center-block">
                        <input type="submit" class="btn btn-info center-block" value="提交">
                    </div>
                </form>
            </div>
        </div>
    </div>
    <script>
        function countTime(obj) {
            obj.attr("disabled", "disabled");
            var count = setInterval(function () {
                obj.attr("value", t + "秒");
                t--;
                if (t < 0) {
                    t = 60;
                    clearInterval(count);
                    obj.removeAttr("disabled");
                    obj.attr("value", "获取验证码");
                }
            }, 1000);
        }
        $(function () {
            $(".btn-get-phone").bind('click', function (e) {
                var _self = this;
                $.post("{:U('User/getPhoneCode')}", {}, function (ret) {
                    layer.msg(ret.info);
                    if (ret.status == 1) {
                        //倒计时
                        countTime($(_self));
                    }
                }, 'json');
            });

            $("form[name='phone_change']").bind('submit', function (e) {
                e.preventDefault();
                var _self = this;
                $.post("{:U('User/reset_pwd')}", $(this).serialize(), function (ret) {
                    layer.msg(ret.info);
                }, 'json');
            });
        })
    </script>
</block>